package com.gopay.bis.dao.corp.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.hibernate.SQLQuery;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.gopay.bis.dao.corp.CustCorpInfoDao;
import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.constants.cust.CustCorpInfoConstants;
import com.gopay.common.domain.cust.CustCorpInfo;

@Repository(value = "custCorpInfoDao")
public class CustCorpInfoDaoImpl extends BaseDAOImpl<CustCorpInfo, String> implements CustCorpInfoDao {

    @Resource(name = "hibernateTemplate")
    protected HibernateTemplate hibernateTemplate;

    @Override
    public Map<String,String> getCustCorpInfo(String custId) {
        Map<String,String> custCropMap = new HashMap<>();
        String sql = "select o.mcc_smer_code,o.corp_name from cust_corp_info o where o.cust_id=? and o.corp_stat='"+CustCorpInfoConstants.CORP_STAT_NORMAL+"'";
        SQLQuery sqQuery = hibernateTemplate.getSessionFactory().openSession().createSQLQuery(sql);
        sqQuery.setParameter(0, custId);
        @SuppressWarnings("unchecked")
        List<Object[]> list = sqQuery.list();
        if(list != null && list.size()>0){
            Object[] obj = list.get(0);
            custCropMap.put("smerId",(String)obj[0]);
            custCropMap.put("merName",(String)obj[1]);
            return custCropMap;
        }
        return null;
        // CustCorpInfo corpInfo = hibernateTemplate.get(CustCorpInfo.class,custId);
        // return corpInfo;

    }

    @Override
    public CustCorpInfo getByCustId(String custId) {
        String hql = " from CustCorpInfo t where t.custId = :custId ";
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("custId", custId);
        List<CustCorpInfo> ss = findByHql(hql, map);
        return (null == ss || 0 == ss.size()) ? null : ss.get(0);
    }

    

}
